/***************************
考核启动
* */
<template>
  <basic-container>
    <el-row>
      <el-button type="primary" @click="addOrEdit">新增</el-button>
    </el-row>
    <el-row>
      <el-table
        style="width: 100%;margin-top:20px"
        :data="dataList"
        border
        stripe
        header-align="center"
        v-loading="dataListLoading"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="index" header-align="center" align="center" label="序号" width="55"></el-table-column>
       <!-- <el-table-column prop="serialNumber" align="center" label="编号" width="150"></el-table-column>-->
        <el-table-column prop="name" align="center" label="日常考核名称" show-overflow-tooltip></el-table-column>
        <el-table-column prop="period" align="center" label="考核周期" show-overflow-tooltip></el-table-column>
        <el-table-column prop="assessBeginTime" align="center" label="开始时间">
          <template slot-scope="scope">
            <span>{{scope.row.assessBeginTime.slice(0,10)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="assessEndTime" align="center" label="结束时间">
          <template slot-scope="scope">
            <span>{{scope.row.assessEndTime.slice(0,10)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="completeBeginTime" align="center" label="填报开始时间">
          <template slot-scope="scope">
            <span>{{scope.row.completeBeginTime.slice(0,10)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="completeEndTime" align="center" label="填报结束时间">
          <template slot-scope="scope">
            <span>{{scope.row.completeEndTime.slice(0,10)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="assessState" align="center" label="工作启动" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-switch
              :active-value="1"
              :inactive-value="0"
              v-model="scope.row.assessState"
              active-color="#13ce66"
              inactive-color="gray"
              @change="workStart(scope.row)"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="completeState" align="center" label="填报启动" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-switch
              :active-value="1"
              :inactive-value="0"
              v-model="scope.row.completeState"
              active-color="#13ce66"
              inactive-color="gray"
              @change="fillInStart(scope.row)"
            ></el-switch>
          </template>
        </el-table-column>

        <el-table-column fixed="right" min-width="120" label="操作">
          <template slot-scope="scope">
            <el-button type="primary" plain size="small" @click="addOrEdit(scope.row)">编辑</el-button>
            <el-button
              v-if="scope.row.assessState==0&&scope.row.completeState==0"
              type="primary"
              plain
              size="small"
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <div class="avue-crud__pagination">
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageData.pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageData.pageSize"
          :total="pageData.totalPage"
          background
          layout="total, sizes, prev, pager, next, jumper"
        ></el-pagination>
      </div>
    </el-row>
    <!-- 新增or编辑 -->
    <addAndEdit
      @refreshDataList="getDataList()"
      v-if="addVisible"
      ref="addNode"
      @closeDialog="closeDialog"
    />
  </basic-container>
</template>

<script>
import addAndEdit from "./addAndEdit"; //组件
import {
  examineList,
  deleteExamine,
  startOrEndExamine,
  startOrEndFillin
} from "@/api/dailyExamine/targetExamine/examineStart"; //接口api
export default {
  data() {
    return {
      addVisible: false, //新增or编辑弹窗显隐
      dataListLoading: false, //表格是否加载
      dataList: [], //表格数组
      multipleSelection: [], //勾选数据
      pageData: {
        //分页对象
        pageIndex: 1, //当前页码
        pageSize: 10, //一页多少条
        totalPage: 0 //总条数
      }
    };
  },
  components: {
    addAndEdit //新增or编辑组件
  },
  created() {
    this.getDataList();
  },
  methods: {
    // 删除
    handleDelete(row) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        deleteExamine(row.id).then(() => {
          this.getDataList();
          this.$notify.success("删除成功");
        });
      });
    },
    // 工作启动
    workStart(data) {
      startOrEndExamine(data.assessState, data.id)
        .then(r => {
          if (r.data.code == 0) {
            this.$message.success("操作成功");
            this.getDataList();
          } else {
            this.$message.error(r.data.msg);
            this.getDataList();
          }
        })
        .catch(err => {
          this.getDataList();
        });
    },
    // 填报启动
    fillInStart(data) {
      startOrEndFillin(data.completeState, data.id)
        .then(r => {
          if (r.data.code == 0) {
            this.$message.success("操作成功");
            this.getDataList();
          } else {
            this.$message.error(r.data.msg);
            this.getDataList();
          }
        })
        .catch(err => {
          this.getDataList();
        });
    },
    // 更新数据
    refreashdata(data) {
      console.log(data);
      if (data == 1) {
        this.getDataList();
      }
    },
    // 查询列表
    getDataList() {
      examineList(
        Object.assign({
          current: this.pageData.pageIndex,
          size: this.pageData.pageSize
        })
      )
        .then(r => {
          if (r.data.code == 0) {
            this.dataList = r.data.data.records;
            this.pageData.totalPage = r.data.data.total;
          }
        })
        .catch(err => {});
    },
    // 新增或者编辑
    addOrEdit(data) {
      this.addVisible = true;
      if (data) {
        this.$nextTick(() => {
          this.$refs.addNode.init(data);
        });
      } else {
        this.$nextTick(() => {
          this.$refs.addNode.init();
        });
      }
    },
    // 勾选数据
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //条数变化
    sizeChangeHandle(val) {
      this.pageData.pageSize = val;
      this.getDataList();
    },
    // 页数变化
    currentChangeHandle(val) {
      this.pageData.pageIndex = val;
      this.getDataList();
    },
    // 关闭新增or编辑弹窗
    closeDialog() {
      this.addVisible = false;
      this.getDataList();
    }
  }
};
</script>

<style lang="scss">
</style>
